import {call, put, all, takeEvery} from 'redux-saga/effects';
import {login, getMenu} from '../resources/services';

function* loginLeatc(action): any {
    try {
        const res = yield call(login, {...action.payload});
        const {code} = res;
        if (code === 0) {
            yield put({
                type: 'LOGIN_SUCCESS',
            });
        }
    } catch (error) {

    }
}

function* getMenuData() {
    const res = yield call(getMenu);
    const {code} = res;
    if (code === 0) {
        yield put({
            type: 'SET_MENU_DATA',
        });
    }
}


function* watchLogin() {
    yield takeEvery('LOGIN_LEATC', loginLeatc);
    yield takeEvery('MENU_LEATC', getMenuData);
}


export default function* counterSagas() {
    yield all([watchLogin()]);
}
